package com.prolestar.strategy.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.prolestar.common.core.domain.model.LoginUser;
import com.prolestar.common.utils.DateUtils;
import com.prolestar.common.utils.ServletUtils;
import com.prolestar.service.TokenServices;
import com.prolestar.strategy.domain.PsPublicsentimentStrategy;
import com.prolestar.strategy.domain.PsPublicsentimentStrategyVO;
import com.prolestar.strategy.mapper.PsPublicsentimentStrategyMapper;
import com.prolestar.strategy.service.IPsPublicsentimentStrategyService;
import com.prolestar.system.service.ISysUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 应对策略Service业务层处理
 * 
 * @author xuyp
 * @date 2022-11-12
 */
@Service
public class PsPublicsentimentStrategyServiceImpl implements IPsPublicsentimentStrategyService 
{
    @Autowired
    private PsPublicsentimentStrategyMapper psPublicsentimentStrategyMapper;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private TokenServices tokenServices;

    /**
     * 查询应对策略
     * 
     * @param id 应对策略主键
     * @return 应对策略
     */
    @Override
    public PsPublicsentimentStrategy selectPsPublicsentimentStrategyById(Long id)
    {

        return psPublicsentimentStrategyMapper.selectPsPublicsentimentStrategyById(id);
    }

    /**
     * 查询应对策略列表
     * 
     * @param psPublicsentimentStrategy 应对策略
     * @return 应对策略
     */
    @Override
    public List<PsPublicsentimentStrategyVO> selectPsPublicsentimentStrategyList(PsPublicsentimentStrategy psPublicsentimentStrategy)
    {

        List<PsPublicsentimentStrategy> strategyList = psPublicsentimentStrategyMapper.selectPsPublicsentimentStrategyList(psPublicsentimentStrategy);

        ArrayList<PsPublicsentimentStrategyVO> strategyArrayList = new ArrayList<>();
        strategyList.forEach(str->{
            PsPublicsentimentStrategyVO strategyVO = new PsPublicsentimentStrategyVO();
            strategyVO.setId(str.getId());
            strategyVO.setStrategyName(str.getStrategyName());
            strategyVO.setIssuesInvolved(str.getIssuesInvolved());
            strategyVO.setStrategyDesc(str.getStrategyDesc());
            strategyVO.setStatus(str.getStatus());
            strategyVO.setCreateBy(sysUserService.selectUserById(str.getCreateBy()).getNickName());
            strategyVO.setCreateTime(str.getCreateTime());
            strategyVO.setUpdateBy(str.getUpdateBy());
            strategyVO.setUpdateTime(str.getUpdateTime());
            strategyArrayList.add(strategyVO);

        });
        return  strategyArrayList;

    }

    /**
     * 新增应对策略
     * 
     * @param psPublicsentimentStrategy 应对策略
     * @return 结果
     */
    @Override
    public int insertPsPublicsentimentStrategy(PsPublicsentimentStrategy psPublicsentimentStrategy)
    {
        LoginUser loginUser = tokenServices.getLoginUser(ServletUtils.getRequest());
        psPublicsentimentStrategy.setCreateBy(loginUser.getUserId());
        psPublicsentimentStrategy.setCreateTime(DateUtils.getNowDate());
        return psPublicsentimentStrategyMapper.insertPsPublicsentimentStrategy(psPublicsentimentStrategy);
    }

    /**
     * 修改应对策略
     * 
     * @param psPublicsentimentStrategy 应对策略
     * @return 结果
     */
    @Override
    public int updatePsPublicsentimentStrategy(PsPublicsentimentStrategy psPublicsentimentStrategy)
    {
        psPublicsentimentStrategy.setUpdateTime(DateUtils.getNowDate());
        return psPublicsentimentStrategyMapper.updatePsPublicsentimentStrategy(psPublicsentimentStrategy);
    }

    /**
     * 批量删除应对策略
     * 
     * @param ids 需要删除的应对策略主键
     * @return 结果
     */
    @Override
    public int deletePsPublicsentimentStrategyByIds(Long[] ids)
    {
        return psPublicsentimentStrategyMapper.deletePsPublicsentimentStrategyByIds(ids);
    }

    /**
     * 删除应对策略信息
     * 
     * @param id 应对策略主键
     * @return 结果
     */
    @Override
    public int deletePsPublicsentimentStrategyById(Long id)
    {
        return psPublicsentimentStrategyMapper.deletePsPublicsentimentStrategyById(id);
    }
}
